﻿<script language="javascript" type="text/javascript" src="<?php echo base_url().'assets/tiny_mce/tiny_mce.js'; ?>"></script>
<script language="javascript" type="text/javascript">
  tinyMCE.init({
    mode : "textareas",
    theme : "advanced",
    editor_deselector : "noEditor",
    entity_encoding : "raw",
    elements : "canswer",
	width : 504,
    
    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,fontsizeselect,forecolor,backcolor,link,unlink,code",
    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",
    theme_advanced_buttons4 : "",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    convert_urls : false,
    file_browser_callback : 'fileManager',
    accessibility_warnings : false
  });
</script>
<div id="pagecontent">
<div id="add" style="cursor:pointer; float:right; font-weight:bold; color:#FF0066;"><span id="actionname" style="text-decoration:overline"><?php echo $this->lang->line('action_new'); ?></span> <img  src="<?php echo base_url(); ?>assets/img/icon-32-new.png" title="<?php echo $this->lang->line('m_addmenu'); ?>" align="absmiddle"/> </div>
<?php 
	if($this->session->flashdata('message')!='')
	{ 
		
?>
<div id="sponsorAdDiv" style="visibility:hidden">
<table width="305px" height="50px" bgcolor="#FF0000"><tr><td>
<table width="300px" height="45px" bgcolor="#FFFFCC"><tr><td align="center" valign="middle">
<?php echo $this->session->flashdata('message'); ?>
</p>
</td></tr></table></td></tr></table>
</div>
<?php
	}
?>
<div id="addfaq">
  <div id='addmenu'> 
<form action="<?php echo base_url().index_page(); ?>/adminpage/process/" method="post" name="adminForm" id="adminForm" autocomplete="off" enctype="multipart/form-data">
    <fieldset style="border:none">
    <div id="addnew"><div align="center" class="error_validate" id="error_message"></div>
      <div>
        <label for="cquestion">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Question</label>
        <input id="cquestion" name="question" type="text" style="width:500px;" maxlength="255" value=""/>
      </div>
      <div>
        <label for="canswer">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Answer</label>
        <textarea id="canswer"  name="answer"   rows="8"></textarea>
      </div>
      <div><br />
        <label for="csorting">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ordering</label>
        <input id="csorting" name="sorting" type="text" size="5" maxlength="4" value="1"/>
      </div>
    </div>
    <input type="hidden" name="component" value="com_faq" />
    <input type="hidden" id="option" name="option" value="add_faq_item" />
    <input type="hidden" name="myurl" value="<?php echo base_url().index_page().$this->uri->uri_string(); ?>" />
    <input type="hidden" id="id" name="id" value="" />
    <input type="hidden" name="task" value="" />
    <div class="toolbar"  align="center">
      <table width="160px" border="0" align="center" cellpadding="5">
        <tr>
          <td align="center"><div id="mybutton" onclick="javascript: submitbutton('save')"><a href="#"><span class="icon-32-save" title="<?php echo $this->lang->line('save'); ?>"></span><?php echo $this->lang->line('save'); ?></a></div></td>
          <td align="center"><div id="mybutton2"><a onclick="document.adminForm.reset()" href="#"><span class="icon-32-cancel" title="<?php echo $this->lang->line('reset'); ?>"> </span><?php echo $this->lang->line('reset'); ?></a></div></td>
        </tr>
      </table>
    </div>
  </fieldset>
</form><div style="padding-left:220px"><br /><hr width="400px" /><br /></div>
  </div> 
</div>

<table width="100%" id="tablesorter-demo" class="tablesorter" border="0" cellpadding="0" cellspacing="1">
  <thead>
  <tr>
    <th align="center" width="25%">Question</th>
    <th align="center" width="55%">Answer</th>
    <th align="center" width="10%">Ordering</th>
    <th align="center" width="10%" class="{sorter: false}"><?php echo $this->lang->line('table_header_action'); ?></th>
  </tr>
  </thead>
  <tbody>
   <?php 
   if(isset($faq_manager))
   {
				$i=0;
				foreach($faq_manager as $faq)
				{
					$td_bg=($i%2==0)?"":" background-color:#f0f0f6";
					echo "<tr><td style='padding-left:10px;".$td_bg.";'><div id='myquestion".$faq['id']."'>".$faq['question']."</div></td><td style='padding-left:10px;".$td_bg.";'><div id='myanswer".$faq['id']."'>".$faq['answer']."</div></td><td  align='center' style='padding-left:10px;".$td_bg.";'><div id='mysorting".$faq['id']."'>".$faq['sorting']."</div></td><td align='center' width='30%' style='padding-left:10px;".$td_bg.";'><a style='color:#FF6600;cursor:pointer'  onclick='show_edit_faq(".$faq['id'].")'>Edit</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a  style='color:#FF3366; text-decoration:underline;cursor:pointer'  onclick='checkdelete(".$faq['id'].")'>Delete</a></td></tr>";
				}
	}
	?> 
  </tbody>
</table>
  </div> 
  <p>&nbsp;</p>
</div>
<script>
function show_edit_faq(id)
{
/*	$.ajax(
	{	
		type: "POST",
		url: "<?php echo base_url().index_page(); ?>/adminpage/cpanel/category_description/"+id,
		success: function(result)
		{
			$("#child"+id).html(result);
	$('#addmenu').toggle(400);
	document.getElementById("option").value="update_faq_item";
		}
	});
*/
	$('#addmenu').show(400);
	document.getElementById("actionname").innerHTML="UPDATE";
	document.getElementById("option").value="update_faq_item";
	document.getElementById("id").value=id;
	document.getElementById("error_message").innerHTML="";
	document.getElementById("cquestion").value=$('#myquestion'+id).html();
	document.getElementById("canswer").value=$('#myanswer'+id).html();
	//alert(document.getElementById("canswer").value);
	document.getElementById("csorting").value=$('#mysorting'+id).html();
	document.getElementById("mybutton").innerHTML='<a href="#"><span class="icon-32-save" title="Update"></span>Update</a>';
	document.getElementById("mybutton2").innerHTML='<a href="<?php echo base_url().index_page()."/adminpage/cpanel/faq/"; ?>"><span class="icon-32-cancel"  title="Cancel this action"> </span>Cancel</span></a>';
	
	tinyMCE.activeEditor.setContent($('#myanswer'+id).html());
}

  $(document).ready(function(){
    $("#addmenu").hide();
	//$("img#vietnam").addClass('activelanguage');
    $("#add").click(function () {
	  //$("#addmenu").show('slow');
	  $('#addmenu').toggle(400); // First click should toggle to 'show'
      return false;

    });
  });
	$(document).ready(function() { 
    $("#tablesorter-demo").tablesorter({ 
        // pass the headers argument and assing a object 
        headers: { 
            // assign the third column (we start counting zero) 
            3: { 
                // disable it by setting the property sorter to false 
                sorter: false 
            } 
        } 
    }); 
});

function checkdelete(id)
{	
	var value = confirm("<?php echo $this->lang->line('meg_confirm') ?>");
	if (value==false)
	{
		return;
	}
	else
	{
		location.href='<?php echo base_url().index_page()."/adminpage/cpanel/delete_faq/"; ?>'+id;
	}
}


/*$('#cmaincontent').change(function() {
    var content = tinyMCE.activeEditor.getContent(); // get the content
    $('#cmaincontent').val(content); // put it in the textarea
});
*/

function checkvalidate() 
{
	canswer=tinyMCE.activeEditor.getContent();   // get the content of Textarea
	
	if ((document.getElementById("cquestion").value == "") || canswer=="")
	{
		document.getElementById("error_message").innerHTML="Question, answer are required.";
		return 0;
	}
	else
	{
		return 1;
	}
}
</script>